package com.ruoyi.web.controller.price;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.service.IGrCardService;
import com.ruoyi.web.domain.GrCard;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@RequestMapping("/price/card")
public class CardController extends BaseController {
    private String prefix = "price/card";

    @Autowired
    private IGrCardService grCardService;

    @GetMapping("/list")
    public String list(GrCard po, ModelMap mmap) {
        startPage();
        List<GrCard> list = grCardService.selectGrCardList(po);
        TableDataInfo table = getDataTable(list);
        mmap.put("grCards", list);
        return prefix + "/list";
    }

    /**
     * 修改角色
     */
    @GetMapping("/edit/{cardId}")
    public String edit(@PathVariable("cardId") Integer cardId, ModelMap mmap){
        mmap.put("card", grCardService.selectCardById(cardId));
        return prefix + "/edit";
    }

    /**
     * 修改保存角色
     */
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(@Validated GrCard role) {
        return toAjax(grCardService.updateGrCard(role));
    }
}
